home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15469 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  54 lines

  1. Path: newshost.gu.edu.au!usenet
  2. From: Student (Student)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: A real basic problem?:  (code!) long integers or compiler problem?
  5. Date: 19 Apr 1996 06:12:30 GMT
  6. Organization: Griffith University
  7. Message-ID: <4l7ase$r44@griffin.itc.gu.edu.au>
  8. References: <4l3mom$f26@newsbf02.news.aol.com> <4l699u$cgo@newsbf02.news.aol.com>
  9. NNTP-Posting-Host: enslab29.student.gu.edu.au
  10. X-Newsreader: WinVN 0.92.5
  11.  
  12.  
  13. This is a tidied up version of your original.
  14. Try it out - it has some small but significant changes.
  15. I haven't compiled it myself - so I don't know if it works
  16. but it should not hang.
  17. The negative values you talked about would be because of %d
  18.  
  19.  
  20. #include <stdio.h>
  21. //#include "local.h"        why do this???
  22.  
  23. long maxlng(void);
  24.  
  25. main(void){
  26.     long i;
  27.     i=maxlng();
  28.     printf("max i= %ld,  max i+1= %ld",i,i+1);
  29. }
  30.  
  31. maxlng(void){
  32.     long first, b;
  33.     first= 10000;
  34.     while (first >= 0){
  35.         b= first;
  36.         printf("b= %ld,  first= %ld\n",b, first);
  37.         first++;
  38.     }
  39.     // why not put the printf here instead of in main?
  40.     // it would avoid some confusing data name changes
  41.     return (b);
  42. }
  43.  
  44.  
  45.  
  46. >
  47. >Whether I change the %d to %ld, does not make any difference.  If I put
  48. >some printf statements in my loop, "first" is negative (!) sometimes
  49. >during this loop even though the "while" statement is only supposed to
  50. >work if "first" is positive!  
  51. >
  52. >Thanks once again!
  53. >
  54.